package com.lost.octopus.test.es7demo.entity.query;

import com.lost.octopus.es.helper.entity.query.aggregation.AggregationStrategy;
import com.lost.octopus.es.helper.entity.query.aggregation.EsAggregations;
import com.lost.octopus.test.es7demo.entity.data.TestSearchVo;

import org.elasticsearch.search.aggregations.AggregationBuilders;

/**
 * 根据手机号分组
 * @author zhangbh
 * @date 2022/10/11 0011 16:29
 */
public class TelGroupAggregationStrategy implements AggregationStrategy<TestSearchVo> {
    @Override
    public EsAggregations use(TestSearchVo query) {
        boolean useTelGroup = query.isUseTelGroup();
        // 当设置为true时，根据联系电话分组
        if (useTelGroup) {
            return new EsAggregations()
                // 联系电话全等的就聚合
                // .addAggregation(AggregationBuilders.topHits("telGroup").storedField("tel").size(1))
                .addAggregation(AggregationBuilders.terms("telGroup1").field("tel"))
                ;
        }
        return null;
    }
}
